package com.cindata

class RiskWarningLevel {

	String name
	String description
	Integer executeCycle

    Workflow workflow

	Date createdDate = new Date()
    Date modifiedDate = new Date()
    User createBy
    User modifyBy

	static hasMany = [rules: RiskWarningLevelRule]

    static mapping = {
        autowire true
    }

    static constraints = {

    	name maxSize: 50, blank: false, unique: true
        description maxSize: 200
        workflow nullable: true, blank: true

    	createdDate nullable: true, blank: true
        modifiedDate nullable: true, blank: true
        createBy nullable: true, blank: true
        modifyBy nullable: true, blank: true
    }

    def springSecurityService
    def beforeInsert()
    {
        def username = springSecurityService?.getPrincipal()?.username
        def user = User.findByUsername(username)
        createBy = user
    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
        def username = springSecurityService?.getPrincipal()?.username
        modifyBy = User.findByUsername(username)
    }
}
